{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-1"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import cv2\n",
    "import numpy as np\n",
    "# 灰色图像直方图均衡化\n",
    "img = cv2.imread('image0.jpg',1)\n",
    "gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)\n",
    "cv2.imshow('gray',gray)\n",
    "dstImg = cv2.equalizeHist(gray)\n",
    "cv2.imshow('dstImg',dstImg)\n",
    "cv2.waitKey(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-1"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 彩色图像直方图均衡化\n",
    "img = cv2.imread('image0.jpg',1)\n",
    "cv2.imshow('img',img)\n",
    "# 颜色通道分解\n",
    "(b,g,r) = cv2.split(img)\n",
    "bHist = cv2.equalizeHist(b)\n",
    "gHist = cv2.equalizeHist(g)\n",
    "rHist = cv2.equalizeHist(r)\n",
    "# 颜色通道合成\n",
    "result = cv2.merge((bHist,gHist,rHist))\n",
    "cv2.imshow('result',result)\n",
    "cv2.waitKey(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-1"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# YUV 直方图均衡化\n",
    "img = cv2.imread('image0.jpg',1)\n",
    "cv2.imshow('img',img)\n",
    "imgYUV = cv2.cvtColor(img,cv2.COLOR_BGR2YCrCb)\n",
    "YUVchannels = cv2.split(imgYUV)\n",
    "YUVchannels[0] = cv2.equalizeHist(YUVchannels[0])\n",
    "channels = cv2.merge(YUVchannels)\n",
    "result = cv2.cvtColor(channels,cv2.COLOR_YCrCb2BGR)\n",
    "cv2.imshow('result',result)\n",
    "cv2.waitKey(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
